//
//  ViewController.m
//  stotyboard豆瓣电影
//
//  Created by z on 16/1/4.
//  Copyright © 2016年 z All rights reserved.
//

#import "ViewController.h"
#import "NetworkHandler.h"
#import "AcModel.h"
#import "BaseModel.h"
#import "acTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "acViewController.h"
@interface ViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong)NSMutableArray *dataArr ;
@property(nonatomic, strong)NSArray *arr;
@property(nonatomic, strong)NSIndexPath *index;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    //数据处理
    [self data];
    
    
}
//数据处理
- (void)data
{
    NSString *str = @"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/activitylist.php";
    [NetworkHandler GETWithURL:str completion:^(id result) {
       
        self.dataArr = result[@"events"];
        self.dataArr = [AcModel modelHanderWithArray:_dataArr];
        [self.tableView reloadData];
    }];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    acTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];

//    NSDictionary *dic = _dataArr[indexPath.row];
//    cell.title.text = dic[@"title"];
//    cell.begin_time.text = dic[@"begin_time"];
//    cell.end_time.text = dic[@"end_time"];
//    cell.address.text = dic[@"address"];
//    cell.category_name.text = dic[@"category_name"];
//    cell.wisher_count.text = [dic[@"wisher_count"] stringValue];
//    cell.participant_count.text = [dic[@"participant_count" ] stringValue];
//    [cell.image sd_setImageWithURL:[NSURL URLWithString:dic[@"image"]]];
//    
    AcModel *m = _dataArr[indexPath.row];
    cell.title.text = m.title;
    cell.begin_time.text = m.begin_time;
    cell.end_time.text = m.end_time;
    cell.participant_count.text = [m.participant_count stringValue];
    cell.wisher_count.text = [m.wisher_count stringValue];
    cell.address.text = m.address;
    cell.category_name.text = m.category_name;
    
    
    [cell.image sd_setImageWithURL:[NSURL URLWithString:m.image]];
    
    
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    
    _index = [_tableView indexPathForCell:sender];
    acViewController *acVC = segue.destinationViewController;
    acVC.colle = _dataArr[_index.row];
}


@end
